package com.zrh.jsd.service.studydemo.ThreadLocalTest;

import java.lang.ref.WeakReference;

public class ThreadLocalLeakTest {
    public static void main(String[] args) {
        String str = new String("1233312123");// 存在强引用str,不会被回收
        WeakReference<String> weakReference = new WeakReference<String>(str);
        System.gc();
        if(weakReference.get() == null){
            System.out.println("已经被回收了");
        }else{
            System.out.println("存在强引用 没有被回收===");
        }

        // 不能存在强引用
        WeakReference<String> weakReference1 = new WeakReference<String>(new String("1233312123"));
        System.gc();
        if(weakReference1.get() == null){
            System.out.println("已经被回收了");
        }else{
            System.out.println("存在强引用 没有被回收===");
        }
    }
}
